﻿using AutoMapper;
using BaseData.API.Write.Applications.AppointmentIng.AppointCommand;
using BaseData.API.Write.DTO;
using BaseData.Domain.Appointment;
using BaseData.ErrorCode;
using BaseData.Infrastructure.Interfaces;
using MediatR;

namespace BaseData.API.Write.Applications.AppointmentIng.AppointCommandHandler
{
    /// <summary>
    /// 反填预约信息
    /// </summary>
    public class AppoinFanCommandHandler : IRequestHandler<AppoinFanCommand, ApiResult<List<AppointDTO>>>
    {
        IBaseRepository<Appointments> appointRep;
        IMapper mapper;
        public AppoinFanCommandHandler(IBaseRepository<Appointments> appointRep, IMapper mapper)
        {
            this.appointRep = appointRep;
            this.mapper = mapper;
        }

        public Task<ApiResult<List<AppointDTO>>> Handle(AppoinFanCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<AppointDTO>> result = new ApiResult<List<AppointDTO>>();
            result.Code = ApiEnum.更新成功;
            result.Message = ApiEnum.更新成功.ToString();

            var list = appointRep.GetAll().Where(s => s.AppointmentId == request.AppointmentId);

            result.Data =mapper.Map<List<AppointDTO>>(list);
            return Task.FromResult(result);
        }
    }
}
